var webpack = require('webpack');
var htmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var CompressionWebpackPlugin = require('compression-webpack-plugin');
module.exports = {
    // devtool: 'source-map',
    devtool: 'false',
    // context:,
    // entry: [__dirname + '/src/script/main.js', __dirname + '/src/script/a.js'],
    // entry: __dirname + '/src/script/main.js',
    entry: {
        c: './src/script/c.js',
        main: './src/script/main.js',
        b: './src/script/b.js',
        a: './src/script/a.js',
        app: './src/script/app.js'

    },
    output: {
        path: __dirname + '/dist',
        filename: 'js/[name].js',
        // publicPath: "/temp/"
        // publicPath: "http//:192.168.31.149:1234/"
    },
    module: {
        loaders: [{
                test: /.\.less$/,
                include: [path.resolve(__dirname, 'src/less')],
                exclude: [path.resolve(__dirname, 'node_modules')],
                // include: './src/',
                // exclude: './node_modules/',
                loader: 'style-loader!css-loader!less-loader'
            },
            {
                test: /\.css$/,
                // include: './src/',
                // exclude: './node_modules/',
                include: [path.resolve(__dirname, 'src/css')],
                exclude: [path.resolve(__dirname, 'node_modules')],
                loader: "style-loader!css-loader"
            },
            {
                test: /\.js$/,
                // include: './src/',
                include: path.resolve(__dirname, 'script'),
                exclude: path.resolve(__dirname, 'node_modules'),
                loader: "babel-loader",
                query: {
                    presets: ['latest']
                }
            }
        ]
    },
    devServer: {
        // contentBase: path.join(__dirname, "dist"),
        contentBase: "./",
        host: '192.168.31.149',
        compress: true,
        color: true,
        port: 1234
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new htmlWebpackPlugin({
            filename: 'a.html',
            template: 'index.html',
            title: '第一个个模板页A',
            inject: "head",
            // inject: false,
            date: new Date(),
            // chunks: ['main', 'a'],
            excludeChunks: ['b', 'c']
            // minify: {
            //     removeComments: true,//删除注释
            //     collapseWhitespace: true//删除空格

            // }
        }),
        new htmlWebpackPlugin({
            filename: 'b.html',
            template: 'index.html',
            title: '第二个模板页B',
            inject: "head",
            // inject: false,
            date: new Date(),
            // chunks: ['main', 'b'],
            excludeChunks: ['a', 'c']
            // minify: {
            //     removeComments: true,
            //     collapseWhitespace: true

            // }
        }),
        new htmlWebpackPlugin({
            filename: 'c.html',
            template: 'index.html',
            title: '第三个模板页C',
            inject: "head",
            // inject: false,
            date: new Date(),
            // chunks: ['main', 'c'],
            excludeChunks: ['b', 'a']
        }),
        new htmlWebpackPlugin({
            filename: 'app.html',
            template: 'index.html',
            title: 'app',
            inject: "head",
            // inject: false,
            date: new Date(),
            chunks: ['app']
            // excludeChunks: ['b', 'a']
        }),
        //在 plugins 中添加 压缩
        new webpack.optimize.UglifyJsPlugin({
            comments: false, //去掉注释
            compress: {
                warnings: false //忽略警告,要不然会有一大堆的黄色字体出现……
            }
        }),
        //在 plugin 中添加  Gzip压缩
        new CompressionWebpackPlugin({ //gzip 压缩
            asset: '[path].gz[query]',
            algorithm: 'gzip',
            test: new RegExp(
                '\\.(js|css)$' //压缩 js 与 css
            ),
            threshold: 10240,
            minRatio: 0.8
        })

        // new webpack.ProvidPlugin({
        //     $: "jquery"
        // }),
        // new webpack.optimize.CommonsChunkPlugin("v", "lib/jquery.min.js") //共享插件块
    ]

}